package top.chukongxiang.monitorservice.config.listener;

import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.stereotype.Component;
import top.chukongxiang.monitorservice.jna.HCNetSDK;

@Component
public class ContextRefreshedListener implements ApplicationListener<ContextRefreshedEvent> {

    public static volatile boolean sdkInitialed = false;

    @Override
    public void onApplicationEvent(ContextRefreshedEvent event) {
        if (!sdkInitialed) {
            ApplicationContext applicationContext = (ApplicationContext) event.getSource();
            HCNetSDK hcNetSDK = applicationContext.getBean(HCNetSDK.class);
            hcNetSDK.NET_DVR_Init();
            sdkInitialed = true;
        }
    }
}
